<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript中的面向对象</title>
</head>
<body>

</body>
<script>
    /*
     * 1. 对象的创建
     * 2. 继承
    * */

    /*   1. 字面量的方式
     *       每次都创建一个全新的对象
    * */
    let employee = {
        name:'Martin',
        age:23,
        gender:'male'
     }
    console.log(employee.age);

    /*
     *  2. 工厂模式
    * */
    function creatEmloyee(name,age) {
        return {
            name:name,
            age:age,
            gender:'male',
            show:function () {
                alert(this.name);
            }
        }
    }

  /*  let employee1 = creatEmloyee('Lee',78);
    console.log(employee1);
    employee1.show();*/

    /**
     *  3.构造器
     *     每一次创建一个实例
     *       属性和方法都是全新
     * */

    function Employee(name,age,gender) {
        this.name = name;
        this.age=age;
        this.gender=gender;
        this.display=function () {
            alert("name:"+this.name+";" +
                "gender:"+this.gender)
        }
    }

    let employee2 = new Employee("M",34,'male');
    let employee3=new Employee('L',45,'female');
    employee2.display();
    employee3.display();

</script>

</html>